<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>文件上传</title>
    <script src="js/jquery.js"></script>
</head>
<body>

<!--//if判断-->
<div th:if="${uploadStatus}" style="color: red" th:text="${uploadStatus}">上传成功</div>

<!--//acition 后为表单内容信息提交到的请求地址（在这里进行对数据的操作）-->
<!--//enctype="multipart/form-data" 表单内容的类型（多媒体类型）-->
<form action="/uploadFile" method="post" enctype="multipart/form-data">
    上传文件:&nbsp;&nbsp;
<!--    //onclick="add()" 绑定一个单击事件的脚本-->
    <input type="button" value="添加文件" onclick="add()"/>
    <div id="file" style="margin-top: 10px;" th:value="文件上传区域"></div>
    <input id="submit" type="submit" value="上传" style="display: none;margin-top: 10px;"/>
</form>

<!--//脚本的语句-->
<script type="text/javascript">

    function add() {
        var innerdiv = "<div>";
        innerdiv += "<input type='file' name='fileUpload' required='required'>" + "<input type='button' value='删除' onclick='remove(this)'>";
        innerdiv += "</div>";
        $("#file").append(innerdiv);
        $("#submit").css("display", "block");
    }


    function remove(obj) {
        $(obj).parent().remove();
        if ($("#file div").length == 0) {
            $("#submit").css("display", "none");
        }
    }


</script>

</body>
</html>